package com.lxq.test1809.Main02;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int max = 1000005;
        int[] a = new int[max];

        int n,ans = 0,x,y;
        n=sc.nextInt();

        for (int i=0;i<2*n;i++){
            x=sc.nextInt();
            y=sc.nextInt();
            for (int j=x+1;j<=y;j++){
                a[j]++;
                if (a[j]==2){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}
